<template>
  <div class="twoMoney">
			<el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="170px" class="demo-ruleForm">
					<div class="list">
						<el-form-item label="营业执照：" prop="businessLicense">
							<upload
								title="上传营业执照"
                imgType="businessLicense"
								:img="ruleForm.businessLicense"
								@success="handleUploadSuccess"
							/>
						</el-form-item>
					</div>
					<div class="list">
						<el-form-item label="开户许可证：" prop="permitForBankAccount">
							<upload
								title="上传开户许可证"
                imgType="permitForBankAccount"
								:img="ruleForm.permitForBankAccount"
								@success="handleUploadSuccess"
							/>
						</el-form-item>
					</div>
					<div class="list">
						<el-form-item label="法人身份证正面：" prop="frontOfIdCard">
							<upload
								title="上传身份证正面"
                imgType="frontOfIdCard"
								:img="ruleForm.frontOfIdCard"
								@success="handleUploadSuccess"
							/>
						</el-form-item>
					</div>
					<div class="list">
						<el-form-item label="法人身份证反面：" prop="backOfIdCard">
							<upload
								title="上传身份证反面"
                imgType="backOfIdCard"
								:img="ruleForm.backOfIdCard"
								@success="handleUploadSuccess"
							/>
						</el-form-item>
					</div>
					<div class="list">
						<el-form-item label="门头照：" prop="singBoard">
							<upload
								title="上传门头照"
                imgType="singBoard"
								:img="ruleForm.singBoard"
								@success="handleUploadSuccess"
							/>
						</el-form-item>
					</div>
					<div class="list">
						<el-form-item label="室内场景照：" prop="interiorPhoto">
							<upload
								title="上传室内场景照"
                imgType="interiorPhoto"
								:img="ruleForm.interiorPhoto"
								@success="handleUploadSuccess"
							/>
						</el-form-item>
					</div>
					<div class="list">
						<el-form-item label="收银台照：" prop="checkoutCounter">
							<upload
								title="上传收银台照"
                imgType="checkoutCounter"
								:img="ruleForm.checkoutCounter"
								@success="handleUploadSuccess"
							/>
						</el-form-item>
					</div>
					<div class="list" v-if="!settleBankType">
						<el-form-item label="法人结算卡：" prop="bankCard">
							<upload
								title="上传法人结算卡"
                imgType="bankCard"
								:img="ruleForm.bankCard"
								@success="handleUploadSuccess"
							/>
						</el-form-item>
					</div>
          <div class="list" v-if="settleBankType">
            <el-form-item label="结算人银行卡：" prop="bankCard">
              <upload
                title="上传结算人银行卡"
                imgType="bankCard"
                :img="ruleForm.bankCard"
                @success="handleUploadSuccess"
              />
            </el-form-item>
          </div>
          <div class="list" v-if="settleBankType">
            <el-form-item label="结算账户指定书：" prop="authorizationForSettlement">
              <upload
                title="上传结算账户指定书"
                imgType="authorizationForSettlement"
                :img="ruleForm.authorizationForSettlement"
                @success="handleUploadSuccess"
              />
            </el-form-item>
          </div>
					<div class="list" v-if="settleBankType">
						<el-form-item label="结算人身份证正面：" prop="settleFrontOfIdCard">
							<upload
								title="上传结算人身份证"
                imgType="settleFrontOfIdCard"
								:img="ruleForm.settleFrontOfIdCard"
								@success="handleUploadSuccess"
							/>
						</el-form-item>
					</div>
					<div class="list" v-if="settleBankType">
						<el-form-item label="结算人身份证反面：" prop="settleBackOfIdCard">
							<upload
								title="上传结算人身份证反面："
                imgType="settleBackOfIdCard"
								:img="ruleForm.settleBackOfIdCard"
								@success="handleUploadSuccess"
							/>
						</el-form-item>
					</div>
					<div class="list" v-if="settleBankType">
						<el-form-item label="结算人手持结算卡：" prop="handheldOfBankCard">
							<upload
								title="上传结算人手持结算卡"
                imgType="handheldOfBankCard"
								:img="ruleForm.handheldOfBankCard"
								@success="handleUploadSuccess"
							/>
						</el-form-item>
					</div>
					<div class="list" v-if="settleBankType">
						<el-form-item label="结算人手持身份证：" prop="handheldOfIdCard">
							<upload
								title="上传结算人手持身份证"
                imgType="handheldOfIdCard"
								:img="ruleForm.handheldOfIdCard"
								@success="handleUploadSuccess"
							/>
						</el-form-item>
					</div>
			</el-form>
  </div>
</template>
<script>
// components
import Upload from '@/components/Upload/index'


export default {
  components: {
    Upload
  },
  props: {
    firstData: Object,
    twoEditData: Object,
    comeType: String,
  },
  data() {
    return {
      ruleForm: {
        businessLicense: '',//营业执照
        permitForBankAccount: '',//开户许可证
        frontOfIdCard: '',//法人身份证正面
        backOfIdCard: '',//法人身份证反面
        singBoard: '',//门头照
        interiorPhoto: '',//室内场景照
        checkoutCounter: '',//收银台照
        bankCard: '',//法人结算卡
        settleFrontOfIdCard: '',//结算人身份证正面
        settleBackOfIdCard: '',//结算人身份证反面
        handheldOfBankCard: '',//手持银行卡照正面
        handheldOfIdCard: '',//手持身份证照
        authorizationForSettlement: '',//结算账户指定书

			},
      files:[],
      settleBankType: '',
			rules: {
        businessLicense: [{ required: true, message: '请上传营业执照', trigger: 'blur' }],
        permitForBankAccount: [{ required: true, message: '请上传开户许可证', trigger: 'blur' }],
        frontOfIdCard: [{ required: true, message: '请上传法人身份证正面', trigger: 'blur' }],
        backOfIdCard: [{ required: true, message: '请上传法人身份证反面', trigger: 'blur' }],
        singBoard: [{ required: true, message: '请上传门头照', trigger: 'blur' }],
        interiorPhoto: [{ required: true, message: '请上传室内场景照', trigger: 'blur' }],
        checkoutCounter: [{ required: true, message: '请上传收银台照', trigger: 'blur' }],
        bankCard: [{ required: true, message: '请上传法人结算卡', trigger: 'blur' }],
        settleFrontOfIdCard: [{ required: true, message: '请上传结算人身份证正面', trigger: 'blur' }],
        settleBackOfIdCard: [{ required: true, message: '请上传结算人身份证反面', trigger: 'blur' }],
        handheldOfBankCard: [{ required: true, message: '请上传结算人手持结算卡', trigger: 'blur' }],
        handheldOfIdCard: [{ required: true, message: '请上传结算人手持身份证', trigger: 'blur' }],
        authorizationForSettlement: [{ required: true, message: '请上传结算账户指定书', trigger: 'blur' }],
      }
    }
  },
  computed: {
   
  },
  created() {
    
	},
  activated(){
    this.fileType()
  },
  mounted(){
    
  },
  methods: {
		// 图片上传
    handleUploadSuccess(data) {
      console.log('data',data)
      
      if(data.imgType == 'businessLicense'){
        this.ruleForm.businessLicense = data.url
        
      }else if(data.imgType == 'permitForBankAccount'){
        this.ruleForm.permitForBankAccount = data.url
        
      }else if(data.imgType == 'frontOfIdCard'){
        this.ruleForm.frontOfIdCard = data.url
       
      }else if(data.imgType == 'backOfIdCard'){
        this.ruleForm.backOfIdCard = data.url
       
      }else if(data.imgType == 'singBoard'){
        this.ruleForm.singBoard = data.url
        
      }else if(data.imgType == 'interiorPhoto'){
        this.ruleForm.interiorPhoto = data.url
        
      }else if(data.imgType == 'checkoutCounter'){
        this.ruleForm.checkoutCounter = data.url
       
      }else if(data.imgType == 'bankCard'){
        this.ruleForm.bankCard = data.url
        
      }else if(data.imgType == 'settleFrontOfIdCard'){
        this.ruleForm.settleFrontOfIdCard = data.url
        
      }else if(data.imgType == 'settleBackOfIdCard'){
        this.ruleForm.settleBackOfIdCard = data.url
        
      }else if(data.imgType == 'handheldOfBankCard'){
        this.ruleForm.handheldOfBankCard = data.url
        
      }else if(data.imgType == 'handheldOfIdCard'){
        this.ruleForm.handheldOfIdCard = data.url
       
      }else if(data.imgType == 'authorizationForSettlement'){
        this.ruleForm.authorizationForSettlement = data.url
        
      }
    },
		// 提交图片切图
    // submitClick() {
    //   this.$refs.form.validate(valid => {
    //     if (valid) {
    //       submitPicture(this.form.applyPicture).then(res => {
    //         this.$emit('success')
    //       })
    //     }
    //   })
    // },
    
    submitForm(formName) {
			this.$refs[formName].validate((valid) => {
				if (valid) {
          this.$emit("twoSuccess",this.ruleForm,'two')
				} else {
					console.log('error submit!!');
					return false;
				}
			});
		},
    //显示法人结算
    fileType(){
      if(this.comeType == 'add'){
        if(this.firstData.settleBankType == 'TOPRIVATE' && this.firstData.legalPerson != this.firstData.accountName){
          this.settleBankType = false
        }else{
          this.settleBankType = true
        }
      }else if(this.comeType == 'edit'){
         console.log('comeType',this.comeType)
         console.log('comeType',this.twoEditData)
        if(this.twoEditData.settleBankType == 'TOPRIVATE' && this.twoEditData.legalPerson != this.twoEditData.accountName){
          this.settleBankType = false
        }else{
          this.settleBankType = true
        }
        console.log('settleBankType',this.twoEditData.files)
    
        
            this.ruleForm.businessLicense = this.twoEditData.credential.businessLicense
          
            this.ruleForm.permitForBankAccount = this.twoEditData.credential.permitForBankAccount
          
            this.ruleForm.frontOfIdCard = this.twoEditData.credential.frontOfIdCard
         
            this.ruleForm.backOfIdCard = this.twoEditData.credential.backOfIdCard
          
            this.ruleForm.singBoard = this.twoEditData.credential.singBoard
         
            this.ruleForm.interiorPhoto = this.twoEditData.credential.interiorPhoto
       
            this.ruleForm.checkoutCounter = this.twoEditData.credential.checkoutCounter
       
            this.ruleForm.bankCard = this.twoEditData.credential.bankCard
           
            this.ruleForm.settleFrontOfIdCard = this.twoEditData.credential.settleFrontOfIdCard
           
            this.ruleForm.settleBackOfIdCard = this.twoEditData.credential.settleBackOfIdCard
          
            this.ruleForm.handheldOfBankCard = this.twoEditData.credential.handheldOfBankCard
        
            this.ruleForm.handheldOfIdCard = this.twoEditData.credential.handheldOfIdCard
            
            this.ruleForm.authorizationForSettlement = this.twoEditData.credential.authorizationForSettlement
            
      }
      
    }
  }
}
</script>
<style lang="scss" scoped>
@import '../style/moneyList';
</style>